<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<%@ include file="/pages/login/common.jsp" %>
<meta http-equiv="X-UA-Compatible" content="IE=8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta content="B2B电商平台" name="description"/>
<meta content="B2B电商平台" name="keyword"/>

<title>B2B电商平台.店铺</title>
<link rel="stylesheet" type="text/css" href="<%=path %>/include/css/global.css" />
<link rel="stylesheet" type="text/css" href="<%=path %>/include/css/style.css" />
<link rel="stylesheet" type="text/css" href="<%=path %>/include/css/btn.css" />
<link rel="stylesheet" type="text/css" href="<%=path %>/include/css/themes.css" />
<link rel="stylesheet" href="<%=path%>/include/JQuery zTree v3.4/css/zTreeStyle/zTreeStyle.css">
<link rel="stylesheet" type="text/css" href="<%=path %>/include/css/register_icss.css" />
<link rel="stylesheet" type="text/css" href="<%=path %>/include/css/mmt_trading.css" />

<script type="text/javascript" src="<%=path %>/include/js/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="<%=path %>/include/js/icss.shop.apply.js"></script>
<script type="text/javascript" src="<%=path %>/include/js/cookies.js"></script>

<script type="text/javascript" src="<%=path %>/include/js/icss.common.js"></script>

<style type="text/css">
body{}
table{border-collapse: collapse;}
tr{ 
    display:block; /*将tr设置为块体元素*/ 
    margin:10px;  /*设置tr间距为2px*/ 
}
td{padding:5px;height:40px; line-height:40px;}
.td1{
	width:55px;
	font-size:12px;
	font-weight:bold;
	text-align:right;
	vertical-align: middle;
}
.input1{
	width:300px;
	height:40px;
	line-height:40px;
	vertical-align:middle;
	float:left;
}
button{
    width:44px;
    height:24px;
    line-height:24px;   
    background-color: transparent;
    background-repeat: no-repeat;
    background-position: 0 -203px;
    border:0;
    cursor:pointer;
    font: 12px/1.5 arial,tahoma,\5b8b\4f53;
    margin: 0 0 0 5px;
    outline:none;
    background-image: url('<%=path%>/include/css/img/xs_bgx.png');   
}
.promptBox{display:inline-block;height:40px;padding-left:5px;width:200px;white-space:nowrap; z-index:50; position:relative;}
.tips-errow{background-position:-296px -22px;color:#f52c2c;}
.tips-ok{background-position:-296px 14px;color:#666;}
.tipsCur{background-position:-296px -55px;color:#666;}
.approveDiv{width:100%;height:23px;margin:0 20px;;padding:15px 0 10px 0;border-bottom: 1px solid #ADADAD;color:blue;}
</style>
<script type="text/javascript">
	$(function(){
		_initSortNum();
	})
	function _initSortNum(){
		var total='${total}';
		var sortNum='${theVipMap.SORT_NUM}';
		var act='${act}';
		var str='';
		if(act=='edit'){
			if(total==0){
				str +='<option value="1" >'+1;
				str +='</option>';
			}else{
				str +='<option selected="selected" value="'+sortNum+'" >'+sortNum;
				str +='</option>';
			}
		}else{
			if(total==0){
				str +='<option value="1" >'+1;
				str +='</option>';
			}else{
				var newSort=parseInt(total)+1;
				str +='<option value="'+newSort+'" >'+newSort;
				str +='</option>';
			}
		}
		$("#sortNum").html(str);
	}
	
	//保存广告信息
	function saveVip(){
		var act='${act}';
		var flag=checkNum(act);
		if(flag){
				parent.swal({
					title: "确定保存吗？", 
					type: "warning",
					showCancelButton: true,
					closeOnConfirm: false,
					cancelButtonText: "取消",
					cancelButtonColor: "#ec6c62",
					confirmButtonText: "是的，我要保存",
					confirmButtonColor: "#ec6c62"
					}, function() {
						$(".tt").each(function() {
								var rule = $(this).attr("rule");
								var array = rule.split("_");
								var obj = array[0];
								pro = array[1];
								$(this).attr("name", obj + "." + pro);
						});
						$.ajax({
				              cache: true,
				              type: "POST",
				              url:'<%=path%>/shopVip/saveVip.do',
				              data:$('#fm').serialize(),
				              async: false,
				              error: function(request) {
				                 parent.swal("系统繁忙，请稍候重试!","", "error");	
				              },
				              success: function(data) {
								data = eval('(' + data + ')');
								var msg = data.msg;
				                if(data.success){
									parent.swal(msg,"", "success");
				                    location.reload();
				             	    window.location.href = '<%=path %>/shopVip/toShopVip.do';
								}else {
									parent.swal(msg,"", "error");
								}
				              }
				         });
					});
			}
	}
	
	//验证输入数值
	function checkNum(act){
			var nextEndMoney='${theNextVipMap.END_MONEY}';
			var nextBegMoney='${theNextVipMap.BEG_MONEY}';
			var nextEndNum='${theNextVipMap.END_NUM}';
			var nextBegNum='${theNextVipMap.BEG_NUM}';
			var onSelectEndMoney=$("#endMoney").val();
			var onSelectEndNum=$("#endNum").val();
			
			var onSelectBegMoney=$("#begMoney").val();
			var onSelectBegNum=$("#begNum").val();
			if(parseInt(nextEndMoney)<parseInt(onSelectEndMoney)){
				var str="下一等级的消费金额为："+nextBegMoney+"~"+nextEndMoney;
				$("#moneyTip").show();
				$("#moneyTip").html(str);
				return false;
			}else if(parseInt(nextEndNum)<parseInt(onSelectEndNum)){
				var str="下一等级的消费次数为："+nextBegNum+"~"+nextEndNum;
				$("#numTip").show();
				$("#numTip").html(str);
				return false;
			}
			if(isNaN(onSelectEndMoney)){
				alert("输入值必须为数字");
				return false;
			}else if(isNaN(onSelectEndNum)){
				alert("输入值必须为数字");
				return false;
			}else if(isNaN(onSelectBegMoney)){
				alert("输入值必须为数字");
				return false;
			}else if(isNaN(onSelectBegNum)){
				alert("输入值必须为数字");
				return false;
			}
		$("#moneyTip").hide();	
		$("#numTip").hide();
		return true;
	}

	function _checkVal(id1,id2){
		var v1 = $("#"+id1).val();
		var v2 = $("#"+id2).val();
		if(isNaN(v2)){
			parent.swal("请填入数字","", "error");
			$("#"+id2).val("");	
		}
		if(parseFloat(v2)<parseFloat(v1)){
			parent.swal("填入数字应比起始数字大","", "error");
			$("#"+id2).val("");	
		}
	}
	
</script>
</head>
<body class="theme-red" data-theme="theme-red" style="padding: 5px;">
	<form id="fm" name="fm" class="form-horizontal form-validate" method="post" action="" novalidate="novalidate">
		<input type="hidden" id="uuid" name="uuid" value="${uuid}">
		<input type="hidden" id="act" name="act" value="${act}">
		<div class="toptil">
			<c:if test="${uuid != null }">
				<span style="font-size:14px;font-weight:bold;">编辑会员设置</span>
			</c:if>
			<c:if test="${uuid == null }">
				<span style="font-size:14px;font-weight:bold;">添加会员设置</span>
			</c:if>
		</div>
		<div style="width:100%;margin-top:20px;margin-left:40px;">
			<table style="width:100%;">
				<tr>
					<td class="td1"  nowrap>VIP编码<font style="color:red;">*</font></td>
					<td width="90%" class="rightTd">
						<input class="tt" style="width:50%;height:38px;" id="groupCode" name=""  rule="shopVip_groupCode" value="${theVipMap.GROUP_CODE }">
					</td>
				</tr>
				<tr>
					<td class="td1" nowrap>VIP名称<font style="color:red;">*</font></td>
					<td width="90%" class="rightTd">
						<input class="tt" id="groupName" name=""  rule="shopVip_groupName" style="width:50%;height:38px;"  value="${theVipMap.GROUP_NAME }">
					</td>
				</tr>
				<tr>
					<td class="td1" nowrap>消费金额<font style="color:red;">*</font></td>
					<td width="90%" class="rightTd">
						<c:if test="${uuid != null }">
							<input class="tt" style="width:22%;height:38px;background-color:#e0e0e0;" id="begMoney"  readonly name=""  rule="shopVip_begMoney"  value="${theVipMap.BEG_MONEY }">
						</c:if>
						<c:if test="${uuid == null }">
							<input class="tt" style="width:22%;height:38px;background-color:#e0e0e0" id="begMoney" readonly="readonly"  name=""  rule="shopVip_begMoney"  value="${thebeforeMap.END_MONEY }">
						</c:if>
						&nbsp;~&nbsp;
						<input class="tt" style="width:22%;height:38px;" id="endMoney"  name="" rule="shopVip_endMoney" onblur="_checkVal('begMoney','endMoney')" value="${theVipMap.END_MONEY }">
						<div class='tips-errow' id="moneyTip" style="display:none;color:red;font-size:14px;margin:0px;"></div>
					</td>
				</tr>
				<tr>
					<td class="td1" nowrap>消费次数<font style="color:red;">*</font></td>
					<td width="90%" class="rightTd">
						<c:if test="${uuid != null }">
							<input class="tt" style="width:22%;height:38px;background-color:#e0e0e0;" id="begNum" readonly name=""  rule="shopVip_begNum"   value="${theVipMap.BEG_NUM }">
						</c:if>
						<c:if test="${uuid == null }">
							<input class="tt" style="width:22%;height:38px;background-color:#e0e0e0;" id="begNum" readonly name=""  rule="shopVip_begNum"   value="${thebeforeMap.END_NUM }">
						</c:if>
						&nbsp;~&nbsp;
						<input class="tt" style="width:22%;height:38px;" id="endNum" name=""  rule="shopVip_endNum" onblur="_checkVal('begNum','endNum')" value="${theVipMap.END_NUM }">
						<div class='tips-errow' id="numTip" style="display:none;color:red;font-size:14px;margin:0px;"></div>
					</td>
				</tr>
				<tr>
					<td class="td1" nowrap style="vertical-align:top;">等级排序<font style="color:red;">*</font></td>
					<td width="90%" class="rightTd">
						<select class="tt" name=""  rule="shopVip_sortNum"   style="height: 38px;width:22%;" id="sortNum" >
							
	                    </select>
					</td>
				</tr>
				<tr>
					<td class="td1" nowrap style="vertical-align:top;">折扣<font style="color:red;">*</font></td>
					<td width="90%" class="rightTd" style="vertical-align:top;">
						<input class="tt" style="width:50%;height:38px;" id="disCount"  name=""  rule="shopVip_disCount"  value="${theVipMap.DISCOUNT }">
					</td>
				</tr>
				<tr>
					<td class="td1" nowrap>&nbsp;</td>
					<td width="90%">
						<div id="btnDiv"> 
						    <button  type="button" onclick="saveVip()">保存</button>
						    <button  type="button" onclick="window.history.go(-1);">返回</button>
							<!-- <a onclick="saveVip();" class="btn btn-primary">保存</a>
							<a onclick="window.history.go(-1);" class="btn">取消</a> -->
						</div>
					</td>
				</tr>
			</table>
		</div>
	</form>
</body>
 <script type="text/javascript">
  $(document).ready(function(){
  		var main = $(window.parent.document).find("#rightFrame");
		var mainheight = $(document).height();
		main.height(mainheight);
  });
  
  </script>
</html>
